<template>
    <div>
        <navBar :navTitle="$t('Jiaoyilishi')" />
        <van-tabs v-model="tabActive" @click="fnChangeTab" swipeable class="tab-deposit tab-bgGray">
            <van-tab :title="$t('Jiaoyi')" name="1">
                <tab1_trade :tabActive="tabActive" v-if="tabActive == 1" />
            </van-tab>

            <van-tab :title="$t('Cunkuan')" name="2">
                <tab2_recharge :transactionArr="transactionArr" :tabActive="tabActive" v-if="tabActive == 2" />
            </van-tab>
            <van-tab :title="$t('Tikuan')" name="3">
                <tab2_recharge :transactionArr="transactionArr" :tabActive="tabActive" v-if="tabActive == 3" />
            </van-tab>
        </van-tabs>
    </div>
</template>

<script>
import { qrecharge_sel_api, Qwithdrawal_sel_api } from "@/assets/js/api";

import tab2_recharge from "@/views/my/my_transaction/tab2_recharge";
import tab1_trade from "@/views/my/my_transaction/tab1_trade";
export default {
    name: "my_transaction_record",
    components: {
        tab1_trade,
        tab2_recharge,
    },
    data() {
        return {
            tabActive: 1,
            tabArr:[],
            /*chongzhi + 体現 数组数据*/
            transactionArr: [],

        }
    },
    methods: {
        /*tab 切换*/
        fnChangeTab(tabActive) {
            console.log(tabActive);
            this.fnGetTabList(tabActive);
        },

        fnGetTabList(tabActive) {
            // if(tabActive == 1){
            //     this.fnGetTrade();
            // }
            if (tabActive == 2) {
                this.fnGetQrecharge();
            }
            if (tabActive == 3) {
                this.fnGetQwith();
            }
        },

        /*提現 查询*/
        fnGetQwith() {
            Qwithdrawal_sel_api().then(res => {
                if (res.code == 200) {
                    this.transactionArr = res.data;
                } else {
                    this.transactionArr = [];
                }
            })
        },

        /*儲值 查询*/
        fnGetQrecharge() {
            qrecharge_sel_api().then(res => {
                if (res.code == 200) {
                    this.transactionArr = res.data;
                } else {
                    this.transactionArr = [];
                }
            })
        },

    },
    created() {
        this.tabArr = [
            {
                id: 1,
                name: "Buôn bán"
            },
            {
                id: 2,
                name: this.$t('Cunkuan')
            }, {
                id: 3,
                name: "Rút tiền"
            },
        ]
        const tabActive = Number(this.$route.query.tabActive);
        if (tabActive) {
            this.tabActive = tabActive;
        }
        this.fnGetTabList(this.tabActive);
    },
}
</script>
